<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema

  xmlns="http://sdk.bt.com/callflow/2007/04"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:ss="http://www.w3.org/2001/10/synthesis"

  targetNamespace="http://sdk.bt.com/callflow/2007/04"
  attributeFormDefault="unqualified" elementFormDefault="qualified">

  <xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="xml.xsd"/>

  <xsd:redefine schemaLocation="synthesis-core.xsd">
    <xsd:complexType name="speak" mixed="true">
      <xsd:complexContent>
        <xsd:restriction base="speak">
          <xsd:group ref="speak.class"/>
          <xsd:attribute name="version" type="version.datatype" fixed="1.0"/>
          <xsd:attribute ref="xml:lang" default="en-UK"/>
        </xsd:restriction>
      </xsd:complexContent>
    </xsd:complexType>

    <xsd:group name="speak.class">
      <xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="meta" type="ssml-meta"/>
          <xsd:element name="metadata" type="ssml-metadata"/>
          <xsd:element name="lexicon"  type="ssml-lexicon"/>
        </xsd:choice>
        <xsd:group ref="sentenceAndStructure.class" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:group>

    <!-- used server side to prevent meta, metadata and lexicon - not acceptable in the c# validation class-->
    <!--<xsd:group name="speak.class">
      <xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="meta" type="ssml-meta" minOccurs="0" maxOccurs="0"/>
          <xsd:element name="metadata" type="ssml-metadata" minOccurs="0" maxOccurs="0"/>
          <xsd:element name="lexicon"  type="ssml-lexicon" minOccurs="0" maxOccurs="0"/>
        </xsd:choice>
        <xsd:group ref="sentenceAndStructure.class" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
    </xsd:group>-->

    <xsd:group name="sentenceAndStructure.class">
      <xsd:sequence>
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:group ref="allowed-within-sentence"/>
          <xsd:group ref="structure"/>
        </xsd:choice>
      </xsd:sequence>
    </xsd:group>

    <xsd:group name="allowed-within-sentence">
      <xsd:choice>
        <xsd:element name="voice" type="voice"/>
        <xsd:element name="prosody" type="prosody"/>
        <xsd:element name="emphasis" type="emphasis"/>
        <xsd:element name="sub" type="sub"/>
        <xsd:element name="say-as" type="say-as"/>
        <xsd:element name="phoneme" type="phoneme"/>
        <xsd:element name="break" type="break"/>
        <xsd:element name="mark" type="mark"/>
      </xsd:choice>
    </xsd:group>

    <xsd:group name="structure">
      <xsd:choice>
        <xsd:element name="p" type="paragraph"/>
        <xsd:element name="s" type="sentence"/>
      </xsd:choice>
    </xsd:group>


  </xsd:redefine>

  <xsd:element name="callflow">
    <xsd:annotation>
      <xsd:documentation>
        The root element for the outbound calls.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence minOccurs="1" maxOccurs="1">
        <xsd:choice minOccurs="0" maxOccurs="unbounded">
          <xsd:element name="announcement" type="announcementType" />
          <xsd:element name="dialog" type="dialogType" />
          <xsd:element name="prompt" type="promptType" />
          <xsd:element name="call" type="callType" />
          <xsd:element name="matchCall" type="matchType" />
          <xsd:element name="dtmf-gen" type="dtmfType" />
          <xsd:element name="pause" type="pauseType" />
          <xsd:element name="hangup" type="hangupType" />
          <xsd:element name="subflow" type="subflowType" />
          <xsd:element name="notification" type="notificationType" />
          <xsd:element name="record" type="recordType" />
        </xsd:choice>
      </xsd:sequence>
      <xsd:attribute name="onCallflowCompletedNotification" type="idRefType" />
    </xsd:complexType>
  </xsd:element>

  <xsd:complexType name="callType">
    <xsd:annotation>
      <xsd:documentation>
        A call can have the "onFinish" and "onFailure" transitions.
        Currently the "onFailure" transition is made when the callee is
        bussy or unavailable. The "onFinish" transition will be made
        after the call was answered.
      </xsd:documentation>
    </xsd:annotation>

    <xsd:complexContent>
      <xsd:extension base="actionType">

        <xsd:attribute name="target" use="required" type="endpointType" />
        <xsd:attribute name="timeout" type="timeoutType" default="30" />

        <xsd:attribute name="next" type="idRefType" />

        <xsd:attribute name="onBusy" type="idRefType" />
        <xsd:attribute name="onUnavailable" type="idRefType" />
        <xsd:attribute name="onNoAnswer" type="idRefType" />

        <xsd:attribute name="onFailure" type="idRefType" />

      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="recordType">
    <xsd:annotation>
      <xsd:documentation>
        Prompts the user with a specified announcement,
        then starts recording, eventually provisioning the recording to "target".
        Press "terminateKey" to end and save it. Optional "next" and "onFailure"
      </xsd:documentation>
    </xsd:annotation>

    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:attribute name="audio" type="audioFileType"/>
        <xsd:attribute name="target" use="required" type="audioFileType" />
        <xsd:attribute name="terminationKey" type="terminationDigitType" />
        <xsd:attribute name="next" type="idRefType" />
        <xsd:attribute name="onFailure" type="idRefType" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="dialogType">
    <xsd:annotation>
      <xsd:documentation>
        Connects the active call with a call given in the "target"
        attribute. A connnection can have the "onFinish" and "onFailure"
        transitions. Currently the "onFailure" transition is made when
        the callee is bussy or unavailable. The "onFinish" transition
        was successfully estblished.
      </xsd:documentation>
    </xsd:annotation>

    <xsd:complexContent>
      <xsd:extension base="callType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="text"
            type="ttsType" />
        </xsd:sequence>
        <xsd:attribute name="audio" type="audioFileType" />
        <xsd:attribute name="init" type="idRefType" />
        <xsd:attribute name="callerDisconnectedAudio"
          type="audioFileType" />
      </xsd:extension>

    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="announcementType">
    <xsd:annotation>
      <xsd:documentation>
        Plays the audio file in given in the "audio" attribute. This tag
        may contain an optional "onFinish" transition.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:sequence>
          <xsd:element maxOccurs="unbounded" minOccurs="0" name="text"
            type="ttsType" />
          <xsd:element name="audio" type="audioType" minOccurs="0" maxOccurs="unbounded"/>
        </xsd:sequence>
        <xsd:attribute name="next" type="idRefType" />
        <xsd:attribute name="audio" type="audioFileType"/>
        <xsd:attribute name="barge" type="xsd:boolean" default="false" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="promptType">
    <xsd:annotation>
      <xsd:documentation>
        Plays the audio file in given in the "audio" attribute and then
        collects the dmft.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="text"	type="ttsType" />
          <xsd:element name="input" type="matchInputType"	minOccurs="0" maxOccurs="unbounded" />
          <xsd:element name="default" type="defaultInputType"	minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
        <xsd:attribute name="audio" type="audioFileType"/>
        <xsd:attribute name="barge" type="xsd:boolean" default="false" />
        <xsd:attribute name="maxDigits" type="maxDigitsType" default="1" />
        <xsd:attribute name="enterKey" type="singleDigitType" />
        <xsd:attribute name="escapeKey" type="singleDigitType" />
        <xsd:attribute name="firstDigitTimeout" type="timeoutType" default="6"/>
        <xsd:attribute name="interDigitTimeout" type="timeoutType" default="6"/>
        <xsd:attribute name="endDigitTimeout" type="timeoutType" default="6"/>
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>



  <xsd:complexType name="dtmfType">
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:attribute name="next" type="idRefType" />
        <xsd:attribute name="digits" type="dtmfDigitsType" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="hangupType">
    <xsd:complexContent>
      <xsd:extension base="actionType" />
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="pauseType">
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:attribute name="seconds" type="xsd:unsignedShort" default="1" />
        <xsd:attribute name="next" type="idRefType" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="notificationType">
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:sequence>
          <xsd:element name="resource" type="resourceType" />
        </xsd:sequence>
        <xsd:attribute name="next" type="idRefType" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="subflowType">
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:sequence>
          <xsd:element maxOccurs="1" minOccurs="0" name="text"
            type="ttsType" />
          <xsd:element maxOccurs="1" minOccurs="0" name="resource"
            type="resourceType" />
        </xsd:sequence>
        <xsd:attribute name="audio" type="audioFileType" />
        <xsd:attribute name="start" type="idRefType" />
        <xsd:attribute name="onFailure" type="idRefType" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>


  <xsd:complexType name="resourceType">
    <xsd:sequence minOccurs="0" maxOccurs="unbounded">
      <xsd:element name="parameter">
        <xsd:complexType>
          <xsd:attribute name="name" type="xsd:string" use="required" />
          <xsd:attribute name="value" type="xsd:string"
            use="required" />
        </xsd:complexType>
      </xsd:element>
    </xsd:sequence>

    <xsd:attribute name="uri" type="xsd:anyURI" use="required" />
    <xsd:attribute name="method" default="GET">
      <xsd:simpleType>
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="GET"></xsd:enumeration>
          <xsd:enumeration value="POST"></xsd:enumeration>
        </xsd:restriction>
      </xsd:simpleType>
    </xsd:attribute>
  </xsd:complexType>

  <xsd:complexType name="matchType">
    <xsd:complexContent>
      <xsd:extension base="actionType">
        <xsd:sequence>
          <xsd:element name="input" type="matchInputType"
            minOccurs="0" maxOccurs="unbounded" />
          <xsd:element name="default" type="defaultInputType"
            minOccurs="0" maxOccurs="1" />
        </xsd:sequence>
        <xsd:attribute name="source" type="matchSource" default="from" />
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>


  <xsd:complexType name="actionType">
    <xsd:annotation>
      <xsd:documentation>
        Base type for all tags that must have the "id" attribute.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:attribute name="id" type="idType" use="required" />
  </xsd:complexType>

  <xsd:complexType name="defaultInputType">
    <xsd:attribute name="next" type="idRefType" use="required" />
  </xsd:complexType>

  <xsd:complexType name="matchInputType">
    <xsd:attribute name="pattern" use="required"/>
    <xsd:attribute name="next" type="idRefType" use="required" />
  </xsd:complexType>

  <xsd:complexType name="ttsType">
    <xsd:complexContent>
      <xsd:extension base="speak">
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

  <xsd:complexType name="audioType">
    <xsd:attribute name="name" use="required" type="audioFileType"/>
  </xsd:complexType>


  <xsd:simpleType name="ttsString">
    <xsd:restriction base="xsd:string">
      <xsd:maxLength value="500"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="audioFileType">
    <xsd:annotation>
      <xsd:documentation>
        Defines the pattern to reference a provisioned audio file.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="(file://)?[a-z, A-Z, 0-9,_,\-]*.*\.wav" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="endpointType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern
        value="(sip:(.+@)?((.+)?)(:\d+)?)|(tel:(\+[\s]*)?([1-9][\d\-\s]+))">
      </xsd:pattern>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="maxDigitsType">
    <xsd:restriction base="xsd:unsignedByte">
      <xsd:minInclusive value="1" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="timeoutType">
    <xsd:restriction base="xsd:unsignedByte">
      <xsd:minInclusive value="1" />
      <xsd:maxInclusive value="120" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="singleDigitType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9,\*,#,\+]" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="dtmfDigitsType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9,\*,#,\+]*" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="terminationDigitType">
    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[0-9,\*,#,A-D,a-d]" />
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:simpleType name="idType">
    <xsd:restriction base="xsd:string" />
  </xsd:simpleType>

  <xsd:simpleType name="idRefType">
    <xsd:restriction base="xsd:string" />
  </xsd:simpleType>

  <xsd:simpleType name="matchSource">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="from" />
      <xsd:enumeration value="to" />
    </xsd:restriction>
  </xsd:simpleType>


</xsd:schema>